package com.brainhealth.web.controller.customer;

import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.customer.domain.ChatParam;
import com.brainhealth.customer.domain.ChatQueryParam;
import com.brainhealth.customer.domain.params.ChatAiParam;
import com.brainhealth.customer.domain.vo.ChatAiContentVO;
import com.brainhealth.customer.service.IAIChatService;
import com.brainhealth.customer.service.IChatService;
import com.brainhealth.customer.service.ICustomerChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wll
 */

@RestController
@RequestMapping("/customer/chat/v1")
public class ChatController extends BaseController {

    @Autowired
    IChatService chatService;

    @Autowired
    IAIChatService aiChatService;

    @Autowired
    ICustomerChatService customerChat;

    @Anonymous
    @GetMapping("/getChatStatus")
    public AjaxResult getChatStatus(HttpServletRequest request) {
        return success(chatService.getChatStatus(request));
    }

    /**
     * 查询AI聊天内容
     */
    @Anonymous
    @PostMapping("/getNextChat")
    public AjaxResult getNextChat(HttpServletRequest request, @RequestBody ChatQueryParam chatQueryParam) {
        return success(chatService.getNextChat(request, chatQueryParam));
    }

    /**
     * 保存AI聊天记录
     *
     * @param chatParam
     * @return
     */
    @Anonymous
    @PostMapping("/saveChatRecord")
    public AjaxResult saveChatRecord(HttpServletRequest request, @RequestBody ChatParam chatParam) {
        return success(chatService.saveChatRecord(request, chatParam));
    }

    /**
     * 查询历史聊天记录
     *
     * @return
     */
    @Anonymous
    @GetMapping("/getChatList")
    public AjaxResult getChatList(HttpServletRequest request) {
        return success(chatService.getChatList(request));
    }

    /**
     * 刷新聊天模板数据
     * @return
     */
    @Anonymous
    @GetMapping("/refreshChatTemplate")
    public AjaxResult refreshChatTemplate() {
        return success(chatService.refreshChatTemplate());
    }

    /**
     * 静止状态，点击弹出对话
     * @param request
     * @return
     */
    @Anonymous
    @GetMapping("/sayHello")
    public AjaxResult sayHello(HttpServletRequest request) {
        return success(chatService.sayHello(request));
    }

    @Anonymous
    @PostMapping("/getChatAiContent")
    public AjaxResult getChatAiContent(HttpServletRequest request, @RequestBody ChatAiParam chatAiParam) {
        ChatAiContentVO chatContent = aiChatService.getChatAiContent(request,chatAiParam);
        if (null == chatContent) {
            return error();
        }
        return success(chatContent);
    }

    // @Anonymous
    // @PostMapping("/insertErnieBotChatContent")
    // public AjaxResult insertErnieBotChatContent(HttpServletRequest request, @RequestBody ChatAiRecordParam chatAiRecordParam) {
    //     Integer result = aiChatService.insertChatAiRecord(request, chatAiRecordParam);
    //     if (null == result) {
    //         return error();
    //     }
    //     return success(result);
    // }

    /**
     * 清理聊天记录
     * @return
     */
    @Anonymous
    @GetMapping("/clearChatRecord")
    public void clearChatRecord() {
         chatService.clearChatRecord();
    }

    @Anonymous
    @GetMapping("/pushLogin")
    public void pushLogin() {
        chatService.pushLogin();
    }

    @Anonymous
    @GetMapping("/openNextTask")
    public void openNextTask() {
        chatService.openNextTask();
    }
}
